{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "column_names=['id','clump thickness', 'uniformity of cell size','uniformity of cell shape','marginal adhesion','single epithelial cell size','bare nuclei','bland chromatin','normal nucleoli','mitoses','class']\n",
    "data = pd.read_csv('breast-cancer-wisconsin.data', names=column_names)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(683, 11)"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data=data.replace(to_replace='?', value=np.nan)\n",
    "data=data.dropna(how='any')\n",
    "data.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2    344\n",
      "4    168\n",
      "Name: class, dtype: int64\n",
      "2    100\n",
      "4     71\n",
      "Name: class, dtype: int64\n"
     ]
    }
   ],
   "source": [
    "from sklearn.model_selection import train_test_split\n",
    "x_train,x_test,y_train,y_test=train_test_split(data[column_names[1:10]],data[column_names[10]],test_size=.25, random_state=33)\n",
    "print(y_train.value_counts())\n",
    "print(y_test.value_counts())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.preprocessing import StandardScaler\n",
    "from sklearn.linear_model import LogisticRegression\n",
    "from sklearn.linear_model import SGDClassifier"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "ss=StandardScaler()\n",
    "x_train=ss.fit_transform(x_train)\n",
    "x_test=ss.fit_transform(x_test)\n",
    "\n",
    "lr=LogisticRegression()\n",
    "sgdc=SGDClassifier()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[2 2 4 4 2 2 2 4 2 2 2 2 4 2 4 4 4 4 4 2 2 4 4 2 4 4 2 2 4 4 4 4 4 4 4 4 2\n",
      " 4 4 4 4 4 2 4 2 2 2 2 2 4 4 2 2 2 4 2 2 2 2 2 4 4 2 2 2 4 2 2 2 2 4 2 2 2\n",
      " 2 2 2 2 4 2 2 2 4 2 2 2 4 2 4 2 4 4 2 2 2 2 4 4 2 2 2 4 2 2 4 2 2 2 2 2 4\n",
      " 2 2 2 2 2 2 4 2 2 2 2 2 4 2 2 2 4 2 2 4 4 2 4 4 2 2 2 2 4 2 4 2 4 2 2 2 2\n",
      " 2 4 4 2 4 4 2 4 2 2 2 2 4 4 4 2 4 2 2 4 2 4 4]\n"
     ]
    }
   ],
   "source": [
    "lr.fit(x_train,y_train)\n",
    "lr_y_predict=lr.predict(x_test)\n",
    "print(lr_y_predict)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[2 2 4 4 2 2 2 4 2 2 2 2 2 2 4 4 4 4 4 2 2 4 4 2 4 4 2 2 4 4 4 4 4 4 4 4 2\n",
      " 4 4 4 4 4 2 4 2 2 4 2 2 4 4 2 2 2 4 2 2 2 2 2 4 4 2 2 2 4 2 2 2 2 4 2 2 2\n",
      " 2 2 2 4 4 2 2 2 4 2 2 2 4 2 4 2 4 4 2 2 2 2 4 4 2 2 2 4 2 2 4 2 2 2 2 2 4\n",
      " 2 2 2 2 2 2 4 2 2 2 4 2 4 2 2 2 4 2 2 4 4 2 4 2 2 2 2 2 4 2 4 2 4 2 2 2 2\n",
      " 2 4 4 2 4 4 2 4 2 2 2 2 4 4 4 2 4 2 2 4 2 4 4]\n"
     ]
    }
   ],
   "source": [
    "sgdc.fit(x_train, y_train)\n",
    "sgdc_y_predict=sgdc.predict(x_test)\n",
    "print(sgdc_y_predict)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "accuracy of lr classifier: 0.964912\n",
      "              precision    recall  f1-score   support\n",
      "\n",
      "      benign       0.95      0.99      0.97       100\n",
      "   malignant       0.99      0.93      0.96        71\n",
      "\n",
      "    accuracy                           0.96       171\n",
      "   macro avg       0.97      0.96      0.96       171\n",
      "weighted avg       0.97      0.96      0.96       171\n",
      "\n"
     ]
    }
   ],
   "source": [
    "from sklearn.metrics import classification_report\n",
    "\n",
    "print('accuracy of lr classifier: %f'%(lr.score(x_test, y_test)))\n",
    "print(classification_report(y_test,lr_y_predict,target_names=['benign','malignant']))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "accuarcy of SGD Classifier: 0.970760\n",
      "              precision    recall  f1-score   support\n",
      "\n",
      "      benign       0.96      0.99      0.98       100\n",
      "   malignant       0.99      0.94      0.96        71\n",
      "\n",
      "    accuracy                           0.97       171\n",
      "   macro avg       0.97      0.97      0.97       171\n",
      "weighted avg       0.97      0.97      0.97       171\n",
      "\n"
     ]
    }
   ],
   "source": [
    "print('accuarcy of SGD Classifier: %f'%(sgdc.score(x_test,y_test)))\n",
    "print(classification_report(y_test,sgdc_y_predict, target_names=['benign', 'malignant']))"
   ]
  }
 ],
 "metadata": {
  "interpreter": {
   "hash": "e0176000adb39a95baec49cdcd8a735b7d5a7201a05d8411fae062bbdd6f3383"
  },
  "kernelspec": {
   "display_name": "Python 3.6.13 64-bit ('ml': conda)",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.13"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
